/**
 * Created by HFY on 2017/3/31.
 */

/**
 * Created by ken on 2015/6/23.
 */
$(function() {
    if($.browser.msie) {
        if($.browser.version<11){
            jQuery.support.cors = true;
        }
    }

    var root_url = $('input[name="root_url"]').val();

    //缓存取值
    var case_year = '';//$.cookie('case_year');
    var case_court = '';//$.cookie('case_court');
    var case_option1 = '';//$.cookie('case_option1');
    var case_option2 = '';//$.cookie('case_option2');

    //整合真正的案件id
    var get_ah = function(is_new_case_court){
        var selectOneValue = $(".select_left_01").val();
        var selectTwoValue = $(".select_left_02").val();
        var selectThreeValue = $(".select_left_03").val();
        var selectFourValue = $(".select_left_04").find("option:selected").text();
        var selectFiveValue = $("#text").val();
        var ah = '';

        if(selectFiveValue == "流水号" || selectFiveValue == "") {
            $(".serial_number").css({
                "display":"block"
            });
            return ah;
        }

        $(".serial_number").css({"display":"none"});

        var is_new = false;
        $.each(is_new_case_court, function(k,v){
            if(v==selectTwoValue){
                is_new = true;
            }
        })

        if(is_new) {
            if( $(".select_left_03").val()== "民事" && $(".select_left_04").find("option:selected").text() == "一审") {
                ah = selectOneValue+selectTwoValue+"民初"+selectFiveValue
            }else if($(".select_left_03").val()== "民事" && $(".select_left_04").find("option:selected").text() == "二审") {
                ah = selectOneValue+selectTwoValue+"民终"+selectFiveValue;
            }else if($(".select_left_03").val()== "刑事" && $(".select_left_04").find("option:selected").text() == "一审") {
                ah = selectOneValue+selectTwoValue+"刑初"+selectFiveValue;
            }else if($(".select_left_03").val()== "刑事" && $(".select_left_04").find("option:selected").text() == "二审") {
                ah = selectOneValue+selectTwoValue+"刑终"+selectFiveValue;
            }else if($(".select_left_03").val()== "行政" && $(".select_left_04").find("option:selected").text() == "一审") {
                ah = selectOneValue+selectTwoValue+"行初"+selectFiveValue;
            }else if($(".select_left_03").val()== "行政" && $(".select_left_04").find("option:selected").text() == "二审") {
                ah = selectOneValue+selectTwoValue+"行终"+selectFiveValue;
            }else if($(".select_left_03").val()== "申诉" && $(".select_left_04").find("option:selected").text() == "刑事") {
                ah = selectOneValue+selectTwoValue+"邢申"+selectFiveValue;
            }else if($(".select_left_03").val()== "申诉" && $(".select_left_04").find("option:selected").text() == "民事") {
                ah = selectOneValue+selectTwoValue+"民申"+selectFiveValue;
            }else if($(".select_left_03").val()== "申诉" && $(".select_left_04").find("option:selected").text() == "行政") {
                ah = selectOneValue+selectTwoValue+"行申"+selectFiveValue;
            }else if($(".select_left_03").val()== "申诉" && $(".select_left_04").find("option:selected").text() == "执行") {
                ah = selectOneValue+selectTwoValue+"执申"+selectFiveValue;
            }else if($(".select_left_03").val()== "执行" && $(".select_left_04").find("option:selected").text() == "普通执行") {
                ah = selectOneValue+selectTwoValue+"执"+selectFiveValue;
            }
        }else {
            if( $(".select_left_03").val()== "民事" && $(".select_left_04").find("option:selected").text() == "一审") {
                ah = selectOneValue+selectTwoValue+"民初字第"+selectFiveValue;
            }else if($(".select_left_03").val()== "民事" && $(".select_left_04").find("option:selected").text() == "二审") {
                ah = selectOneValue+selectTwoValue+"民终字第"+selectFiveValue;
            }else if($(".select_left_03").val()== "刑事" && $(".select_left_04").find("option:selected").text() == "一审") {
                ah = selectOneValue+selectTwoValue+"刑初字第"+selectFiveValue;
            }else if($(".select_left_03").val()== "刑事" && $(".select_left_04").find("option:selected").text() == "二审") {
                ah = selectOneValue+selectTwoValue+"刑终字第"+selectFiveValue;
            }else if($(".select_left_03").val()== "行政" && $(".select_left_04").find("option:selected").text() == "一审") {
                ah = selectOneValue+selectTwoValue+"行初字第"+selectFiveValue;
            }else if($(".select_left_03").val()== "行政" && $(".select_left_04").find("option:selected").text() == "二审") {
                ah = selectOneValue+selectTwoValue+"行终字第"+selectFiveValue;
            }else if($(".select_left_03").val()== "申诉" && $(".select_left_04").find("option:selected").text() == "刑事") {
                ah = selectOneValue+selectTwoValue+"邢申字第"+selectFiveValue;
            }else if($(".select_left_03").val()== "申诉" && $(".select_left_04").find("option:selected").text() == "民事") {
                ah = selectOneValue+selectTwoValue+"民申字第"+selectFiveValue;
            }else if($(".select_left_03").val()== "申诉" && $(".select_left_04").find("option:selected").text() == "行政") {
                ah = selectOneValue+selectTwoValue+"行申字第"+selectFiveValue;
            }else if($(".select_left_03").val()== "申诉" && $(".select_left_04").find("option:selected").text() == "执行") {
                ah = selectOneValue+selectTwoValue+"执申字第"+selectFiveValue;
            }else if($(".select_left_03").val()== "执行" && $(".select_left_04").find("option:selected").text() == "普通执行") {
                ah = selectOneValue+selectTwoValue+"执字第"+selectFiveValue;
            }
        }
        return ah+'号';
    }


    //新的法院代码
    var is_new_case_court = [];

    //关联年份跟法院名称
    var selectLeftOne_obj = $(".select_left_01");
    var selectLeftTwo_obj = $(".select_left_02");
    function years(is_new_case_court) {
        if (selectLeftOne_obj.val() == "（2017）" || selectLeftOne_obj.val() == "（2016）") {
            if(is_new_case_court){
                selectLeftTwo_obj.val(is_new_case_court[0]);
            }
        }else {
            if(selectLeftTwo_obj.get(0).options.length>1){
                selectLeftTwo_obj.val(selectLeftTwo_obj.get(0).options[1].value);
            }
        }
    }

    var fy_code = '';
    //刷新后请求用户的法庭代码
    $.ajax({
        url: root_url+'/@zopen.ocr_beta:get_case',
        cache: false,
        data: {},
        dataType: 'json',
        type: 'post',
        crossDomain: true,
        success: function (data) {
            if(data.status){
                var str = '';
                $.each(data.res, function(k,v){
                    str += '<option>'+v+'</option>';
                });
                $('.select_left_02').html(str);
                is_new_case_court = data.is_new;

                //缓存有值则赋值
                if(case_year){
                    $('.select_left_01').val(case_year)
                }
                if(case_court){
                    $('.select_left_02').val(case_court);
                }
                if(case_option1){
                    $('.select_left_03').val(case_option1);
                }
                if(case_option2){
                    $('.select_left_04').val(case_option2);
                }

                years(is_new_case_court);
                fy_code = data.fy_code;
            }
        },
        error: function(){

        }
    });

    //变化时
    selectLeftOne_obj.change(function() {
        years(is_new_case_court);
    });

    //轮询分类状态
    var get_dategory_status = function(){
        $.ajax({
            url: root_url+'/@zopen.ocr_beta:get_category_status',
            cache: false,
            data: {},
            dataType: 'json',
            type: 'post',
            crossDomain: true,
            success: function (data) {
                var t = 3000;
                if(data.status){
                    if(data.res.length>0){
                        t = 0;
                        $(".classify").css({'display':'block', "height":"0"});
                        $.each(data.res, function(k, v){
                            setTimeout(function(){
                                $('.classify').find('.classify_ah').html(v.ah);
                                $('.classify').find('.classify_status').html(v.handle_status);
                                $(".classify").animate({height:"50px"}, 500, function(){
                                    setTimeout(function(){
                                        $(".classify").animate({height:"0"},500);
                                    }, 3000);
                                });
                            }, t);
                            t += 4000;
                        });
                    }
                }
                setTimeout(function(){
                    get_dategory_status();
                }, t);
            },
            error: function(){
                setTimeout(function(){
                    get_dategory_status();
                }, 10000);
            }
        });
    }
    get_dategory_status();

    //轮询查次数
    var get_file_num = function(){
        $.ajax({
            url: root_url+'/@zopen.ocr_beta:get_file_count',
            cache: false,
            data: {},
            dataType: 'json',
            type: 'post',
            crossDomain: true,
            success: function (data) {
                if(data.status){
                    if(data.res.length>0){
                        var str = '';
                        $.each(data.res, function(k, v){
                            if(str){
                                str += '<br/>';
                            }
                            str += '上传页数: '+v.num+'页<br>';
                        });
                        str += '是否继续上传本案?';
                        $('.succeed').find('.sucdeed_span_02').html(str);
                        $('.succeed').find('.sucdeed_div_a').css({'display':'inline-block'});
                        $('.succeed').find('.sucdeed_div_a1').css({'display':'inline-block'});
                        $('.succeed').find('.sucdeed_div_a2').css({'display':'none'});
                    }else{
                        setTimeout(function(){
                            get_file_num();
                        }, 1000);
                    }
                }else{
                    setTimeout(function(){
                        get_file_num();
                    }, 1000);
                }
            },
            error: function(){

            }
        });
    }

    //扫描上传按钮时 验证案件号是否存在
    $('.scan_a').click(function(){
        var ah = get_ah(is_new_case_court);
        var is_disabled = $('.scan_a').attr('disabled');
        if(ah&&!is_disabled){
            $('.scan_a').attr('disabled', true);
            $.ajax({
                url: root_url+'/@zopen.ocr_beta:query_bh',
                cache: false,
                data: {'ah': ah, 'fy_code':fy_code},
                dataType: 'json',
                type: 'post',
                crossDomain: true,
                success: function (data) {
                    if(data.status){
                        //   var new_case_year = $('.select_left_01').val();
                        //         	var new_case_court = $('.select_left_02').val();
                        //         	var new_case_option1 = $('.select_left_03').val();
                        //         	var new_case_option2 = $('.select_left_04').val();
                        // $.cookie('case_year', new_case_year, {expires: 7});
                        //     		$.cookie('case_court', new_case_court, {expires: 7});
                        //     		$.cookie('case_option1', new_case_option1, {expires: 7});
                        //     		$.cookie('case_option2', new_case_option2, {expires: 7});
                        $(".find").find('.find_top_ye').css('display','none');
                        $(".find").find('.find_top_message').css('display','none');
                        $(".find").css({"display":"block"});
                        $(".defeated").css({"display":"none"});
                        $(".find").find('.find_top_ah').html(ah);
                        $(".find").find('.find_top_ren').html(data.res[2]);
                        if(data.res.length>3){
                            $(".find").find('.find_top_ye').css('display','block');
                            $(".find").find('.find_top_ye_num').html(data.res[3]);
                        }else{
                            $(".find").find('.find_top_message').css('display','block').html(data.message);
                        }
                    }else{
                        $(".defeated2").css({"display":"block"});
                        $(".find").css({"display":"none"});
                        $(".defeated2").find('.defeated_top_ah').html(ah);
                        $(".defeated2").find('.defeated_top_message').html(data.message);
                    }
                },
                error: function(){
                    $(".defeated2").css({"display":"block"});
                    $(".find").css({"display":"none"});
                    $(".defeated2").find('.defeated_top_ah').html(ah);
                    $(".defeated2").find('.defeated_top_message').html('请求无效');
                },
                complete: function(){
                    $('.scan_a').attr('disabled', false);
                }
            });
        }
    });

    //打开扫描上传 封装函数
    var affirm_scan = function(ah){
        $.base64.utf8encode = true;
        var ah_encode = $.base64.btoa(ah);

        var redict_url = root_url+'/@zopen.ocr_beta:scan_upload?caseAH='+ah_encode;
        var win = window.open(redict_url, '_blank');
        if(win){
            win.focus();
        }else{
            alert('请允许打开新的标签页');
        }

        $('.from_type').val('scan');
        $('.succeed').find('.success_ah_value').val(ah);
        $(".find").css({"display":"none"});
        $(".obscure").css({"display":"none"});
        $('.succeed').find('.sucdeed_span_01').html(ah);
        $('.succeed').find('.sucdeed_span_02').html('正在扫描上传中<br>请稍候...');
        $('.succeed').find('.sucdeed_div_a').css({'display':'none'});
        $('.succeed').find('.sucdeed_div_a1').css({'display':'none'});
        $('.succeed').find('.sucdeed_div_a2').css({'display':'inline-block'});
        $('.succeed').css({'display':'block'});
        //轮询当前上传页数
        get_file_num();
    }
    //扫描上传 确认上传
    $('.affirm').click(function(){
        var ah = get_ah(is_new_case_court);
        affirm_scan(ah);
    });

    //本地上传时 验证案件号是否存在
    $('.scan_a_02').click(function(){
        var ah = get_ah(is_new_case_court);
        var is_disabled = $('.scan_a_02').attr('disabled');
        if(ah&&!is_disabled){
            $('.scan_a_02').attr('disabled', true);
            $.ajax({
                url: root_url+'/@zopen.ocr_beta:query_bh',
                cache: false,
                data: {'ah': ah, 'fy_code':fy_code},
                dataType: 'json',
                type: 'post',
                crossDomain: true,
                success: function (data) {
                    if(data.status){
                        //   var new_case_year = $('.select_left_01').val();
                        //         	var new_case_court = $('.select_left_02').val();
                        //         	var new_case_option1 = $('.select_left_03').val();
                        //         	var new_case_option2 = $('.select_left_04').val();
                        // $.cookie('case_year', new_case_year, {expires: 7});
                        //     		$.cookie('case_court', new_case_court, {expires: 7});
                        //     		$.cookie('case_option1', new_case_option1, {expires: 7});
                        //     		$.cookie('case_option2', new_case_option2, {expires: 7});
                        $(".Web_upload").find('.find_top_ye').css('display','none');
                        $(".Web_upload").find('.find_top_message').css('display','none');
                        $(".Web_upload").css({"display":"block"});
                        $(".defeated").css({"display":"none"});
                        $(".Web_upload").find('.find_top_ah').html(ah);
                        $(".Web_upload").find('.find_top_ren').html(data.res[2]);
                        if(data.res.length>3){
                            $(".Web_upload").find('.find_top_ye').css('display','block');
                            $(".Web_upload").find('.find_top_ye_num').html(data.res[3]);
                        }else{
                            $(".Web_upload").find('.find_top_message').css('display','block').html(data.message);
                        }
                    }else{
                        $(".defeated2").css({"display":"block"});
                        $(".Web_upload").css({"display":"none"});
                        $(".defeated2").find('.defeated_top_ah').html(ah);
                        $(".defeated2").find('.defeated_top_message').html(data.message);
                    }
                },
                error: function(){
                    $(".defeated2").css({"display":"block"});
                    $(".Web_upload").css({"display":"none"});
                    $(".defeated2").find('.defeated_top_ah').html(ah);
                    $(".defeated2").find('.defeated_top_message').html('请求无效');
                },
                complete: function(){
                    $('.scan_a_02').attr('disabled', false);
                }
            });
        }
    });

    //本地上传 封装函数
    var affirm_local_upload = function(ah){
        var is_disabled = $('.affirm_two').attr('disabled');
        if(ah&&!is_disabled){
            $('.affirm_two').attr('disabled', true).css('cursor','default');
            $.ajax({
                url: root_url+'/@zopen.ocr_beta:sso',
                cache: false,
                data: {'caseAH': ah},
                dataType: 'json',
                type: 'get',
                crossDomain: true,
                success: function (d) {
                },
                error: function(){
                },
                complete: function(){
                    $('.affirm_two').attr('disabled', false).css('cursor','pointer');
                    $('.from_type').val('local');
                    $('.succeed').find('.success_ah_value').val(ah);
                    $(".Web_upload").css({"display":"none"});
                    $(".obscure").css({"display":"none"});
                    $('.succeed').find('.sucdeed_span_01').html(ah);
                    $('.succeed').find('.sucdeed_span_02').html('正在上传中<br>请稍候...');
                    $('.succeed').find('.sucdeed_div_a').css({'display':'none'});
                    $('.succeed').find('.sucdeed_div_a1').css({'display':'none'});
                    $('.succeed').find('.sucdeed_div_a2').css({'display':'inline-block'});
                    $('.succeed').css({'display':'block'});
                    //轮询当前上传页数
                    get_file_num();
                }
            });
        }
    }
    //本地上传 确认上传
    $('.affirm_two').click(function(){
        var ah = get_ah(is_new_case_court);
        affirm_local_upload(ah);
    });

    //本案继续上传
    $('.sucdeed_div_a').click(function(){
        var obj = $(this).parent().parent();
        var from_type = obj.find('.from_type').val();
        var ah = obj.find('.success_ah_value').val();
        if(from_type=='local'){
            affirm_local_upload(ah);
        }else if(from_type=='scan'){
            affirm_scan(ah);
        }
    });

    //别案上传
    $('.sucdeed_div_a1').click(function(){
        $("#succeed").css({"display": "none"});
        $('#text').val('');
    });

    //取消本案上传
    //@zopen.ocr_beta:test是测试的脚本,正式用请替换
    //不停的请求，直到取消成功
    var cancel_upload = function(){
        $.ajax({
            url: root_url+'/@zopen.ocr_beta:test',
            cache: false,
            data: {},
            dataType: 'json',
            type: 'post',
            crossDomain: true,
            success: function (data) {
                if(!data.status){
                    setTimeout(function(){
                        cancel_upload();
                    }, 5000);
                }
            },
            error: function(){
                setTimeout(function(){
                    cancel_upload();
                }, 5000);
            }
        });
    }
    $('.sucdeed_div_a2').click(function(){
        $("#succeed").css({"display": "none"});
        cancel_upload();
    });

    //本地成功后可以关闭
    $(".abolish_two").click(function () {
        $(".Web_upload").css({"display": "none"});
        $('#text').val('');
    });
    //失败后关闭
    $('.defeated_return').click(function(){
        $(".defeated").css({"display":"none"});
        $(".defeated2").css({"display":"none"});
    });
    //成功后可以关闭
    $('.abolish').click(function(){
        $(".find").css({"display":"none"});
        $('#text').val('');
    });
    //成功后点击关闭
    $("#sucdeed_top_a").click(function () {
        $("#succeed").css({"display": "none"});
    });

    //查询日志 封装函数
    var get_oplog = function(page){
        $.ajax({
            url: root_url+'/@zopen.ocr_beta:get_oplog',
            cache: false,
            data: {'page': page},
            dataType: 'json',
            type: 'get',
            crossDomain: true,
            success: function (data) {
                var batch_html = '';
                if(data.status){
                    var str = '';
                    $.each(data.res, function(k,v){
                        str += '<ul>'+
                            '<li>'+v.ah+'</li>'+
                            '<li>'+v.count+'</li>'+
                            '<li>'+v.handle_status+'</li>'+
                            '<li>'+v.created+'</li>'+
                            '</ul>';
                    });
                    $('.operate').find('.operate_nav_ul').html(str);
                    batch_html = $('.operate').find('.js-page').html(data.batch_html);
                }else{
                    $('.operate').find('.operate_nav_ul').html('<ul><li>'+data.message+'</li></ul>');
                    batch_html = $('.operate').find('.js-page').html(data.batch_html);
                }

                if(batch_html){
                    batch_html.find('.page-no').click(function(){
                        var page = $(this).attr('id');

                        var prev = 1;
                        var next = 1;
                        var last = $(this).parent().parent().find('.last').find('.page-no').attr('id');
                        if(parseInt(last) > 1){
                            if(parseInt(page) > 1){
                                prev = parseInt(page) - 1;
                            }

                            if(parseInt(page) < parseInt(last)){
                                next = parseInt(page) + 1;
                            }else{
                                next = last;
                            }
                        }

                        $(this).parent().parent().find('.prev').find('.page-no').attr('id', prev);
                        $(this).parent().parent().find('.next').find('.page-no').attr('id', next);
                        $(this).parent().parent().find('.page-'+page).addClass('active').siblings('.page').removeClass('active');

                        get_oplog(page);
                    });
                }
            },
            error: function(){
                $('.operate').find('.operate_nav_ul').html('<ul><li>请求发生错误</li></ul>');
                $('.operate').find('.js-page').html('');
            }
        });
    }

    //进入日志页面，查询日志
    $('.nav').find('.nav-oplog').click(function(){
        var page = '1';
        get_oplog(page);
    });

    //按页数查询日志
    $('.page-no').click(function(){
        var page = $(this).attr('id');

        var prev = 1;
        var next = 1;
        var last = $(this).parent().parent().find('.last').find('.page-no').attr('id');
        if(parseInt(last) > 1){
            if(parseInt(page) > 1){
                prev = parseInt(page) - 1;
            }

            if(parseInt(page) < parseInt(last)){
                next = parseInt(page) + 1;
            }else{
                next = last;
            }
        }

        $(this).parent().parent().find('.prev').find('.page-no').attr('id', prev);
        $(this).parent().parent().find('.next').find('.page-no').attr('id', next);
        $(this).parent().parent().find('.page-'+page).addClass('active').siblings('.page').removeClass('active');

        get_oplog(page);

    });

    //模糊搜索
    var search_ah_page = function(ah, court, page){
        $('.more').find('.js-page').html('');
        $.ajax({
            url: root_url + '/@zopen.ocr_beta:get_ah_list',
            cache: false,
            data: {"ah": ah, "court": court, "is_close": '1', "page": page},
            dataType: 'json',
            type: 'get',
            crossDomain: true,
            success: function (data) {
                $('.more').find('.more_center').html('');
                if(data.status){
                    $.each(data.res, function(k,v){
                        var str = '<ul class="more_center_ul">'+
                            '<li class="more_center_ah">'+v.ah+'</li>'+
                            '<li class="more_center_name">'+v.cbrmc+'&nbsp;</li>'+
                            '<li class="more_center_time">'+v.jarq+'&nbsp;</li>'+
                            '<li class="more_center_uploading"><a href="javascript:;">'+
                            '补充上传'+
                            '</a></li>'+
                            '</ul>';

                        var obj = $('.more').find('.more_center').append(str);
                        obj.find('.more_center_uploading').click(function(){
                            $('.obscure').css('display','block');
                            $('.obscure').find('.obscure_ah').html(v.ah);
                            $('.obscure').find('.agent').html(v.cbrmc);
                            $('.obscure').find('.register').html(v.larq);
                            $('.obscure').find('input[name="obscure_ah_value"]').val(v.ah);
                        });
                    });

                    var batch_html_obj = $('.more').find('.js-page').html(data.batch_html);
                    batch_html_obj.find('.page-no').click(function(){
                        var no_data_message = '<ul class="more_center_ul" style="width: 100%;">'+
                            '<li style="text-align:center;width: 100%;">正在查询中, 请稍候...</li>'+
                            '</ul>';
                        $('.more').find('.more_center').html(no_data_message);

                        var page = $(this).attr('id');

                        var prev = 1;
                        var next = 1;
                        var last = $(this).parent().parent().find('.last').find('.page-no').attr('id');
                        if(parseInt(last) > 1){
                            if(parseInt(page) > 1){
                                prev = parseInt(page) - 1;
                            }

                            if(parseInt(page) < parseInt(last)){
                                next = parseInt(page) + 1;
                            }else{
                                next = last;
                            }
                        }

                        $(this).parent().parent().find('.prev').find('.page-no').attr('id', prev);
                        $(this).parent().parent().find('.next').find('.page-no').attr('id', next);
                        $(this).parent().parent().find('.page-'+page).addClass('active').siblings('.page').removeClass('active');

                        search_ah_page(ah, court, page);
                    });
                }else{
                    var no_data_message = '<ul class="more_center_ul" style="width: 100%;">'+
                        '<li style="text-align:center;width: 100%;">'+data.message+'</li>'+
                        '</ul>';
                    $('.more').find('.more_center').html(no_data_message);
                    $('.more').find('.js-page').html('');
                }
            },
            error: function(){
                var no_data_message = '<ul class="more_center_ul" style="width: 100%;">'+
                    '<li style="text-align:center;width: 100%;">请求发生错误!</li>'+
                    '</ul>';
                $('.more').find('.more_center').html(no_data_message);
                $('.more').find('.js-page').html('');
            }
        });
    }

    var search_ah = function(ah, court, is_close, page){
        if(ah=='请输入案号流水号'){
            ah = '';
        }
        if(is_close=='not'){
            is_close_value = '.hint';
            is_close = '';
        }else{
            is_close = '1';
            is_close_value = '.hint_two';
        }
        $('.dim').find(is_close_value).find('.hint_check').css('display','none');
        $('.dim').find(is_close_value).css('display','block');
        $('.dim').find(is_close_value).find('ul').html('');

        if(ah){
            $('.dim').find(is_close_value).find('ul').html('<li><a href="javascript:;">正在查询...</a></li>');
            $.ajax({
                url: root_url + '/@zopen.ocr_beta:get_ah_list',
                cache: false,
                data: {"ah": ah, "court": court, "is_close": is_close, "page": page},
                dataType: 'json',
                type: 'get',
                crossDomain: true,
                success: function (data) {
                    $('.dim').find(is_close_value).find('ul').html('');
                    if(data.status){
                        $.each(data.res, function(k,v){
                            var str = '<li>'+
                                '<a href="javascript:;" class="dim-ah" data-attr="'+v.ah+'">'+v.ah;
                            if(v.cbrmc){
                                str += '('+v.cbrmc+')';
                            }
                            str += '</a></li>';

                            var obj = $('.dim').find(is_close_value).find('ul').append(str);
                            obj.find('.dim-ah').click(function(){
                                $('.obscure').css('display','block');
                                $('.obscure').find('.obscure_ah').html(v.ah);
                                $('.obscure').find('.agent').html(v.cbrmc);
                                $('.obscure').find('.register').html(v.larq);
                                $('.obscure').find('input[name="obscure_ah_value"]').val(v.ah);
                            });
                        });
                        if(data.res.length>0&&is_close){
                            $('.dim').find(is_close_value).find('.hint_check').css('display','block');
                        }
                    }else{
                        var str = '<li><a href="javascript:;">'+data.message+'</a></li>';
                        $('.dim').find(is_close_value).find('ul').html(str);
                    }
                },
                error: function(){
                    var str = '<li><a href="javascript:;">请求发生错误</a></li>';
                    $('.dim').find(is_close_value).find('ul').html(str);
                }
            });
        }
    }

    $('.dim').find('.dim_input').keyup(function(){
        var current = $(this);
        var dim_input = current.val();
        setTimeout(function(){
            var dim_input2 = current.val();
            if(dim_input2==dim_input){
                var is_close = current.parent().parent().find('.dim_select').val();
                search_ah(dim_input2, fy_code, is_close, 1);
            }
        }, 500);
    });

    $('.dim').find('.dim_select').change(function(){
        var current = $(this);
        var is_close = current.val();
        var dim_input = current.parent().parent().find('.dim_input').val();
        search_ah(dim_input, fy_code, is_close, 1);
    });

    $('.obscure').find('.obscure_scan_a').click(function(){
        var ah = $(this).parent().find('input[name="obscure_ah_value"]').val();
        affirm_scan(ah);
    });

    $('.obscure').find('.obscure_scan_a_02').click(function(){
        var ah = $(this).parent().find('input[name="obscure_ah_value"]').val();
        affirm_local_upload(ah);
    });

    $('.dim').find('.hint_check').click(function(){
        var dim_input = $('.dim').find('.dim_input').val();
        var redict_url = root_url+'/@zopen.ocr_test:index?dim_input='+dim_input;
        var win = window.open(redict_url, '_blank');
        if(win){
            win.focus();
        }else{
            alert('请允许打开新的标签页');
        }
    });

    var more_dim_input = $('.more_dim_input').val();
    var settimeout = function(){
        if(fy_code){
            search_ah_page(more_dim_input, fy_code, 'then', 1);
        }else{
            setTimeout(function(){
                settimeout();
            }, 1000);
        }
    }
    if(more_dim_input){
        var no_data_message = '<ul class="more_center_ul" style="width: 100%;">'+
            '<li style="text-align:center;width: 100%;">正在查询中, 请稍候...</li>'+
            '</ul>';
        $('.more').find('.more_center').append(no_data_message);
        settimeout();
    }

    //请求信任桌面助手
    var server = $('input[name="server"]').val();
    var message_server = $('input[name="message_server"]').val();
    var oc_server = $('input[name="oc_server"]').val();
    var account = $('input[name="account"]').val();
    var instance = $('input[name="instance"]').val();
    var pid = $('input[name="uid"]').val();
    var token = $('input[name="token"]').val();
    var instance_name = $('input[name="instance_name"]').val();
    var instance_url = $('input[name="instance_url"]').val();
    var allow_script = $('input[name="allow_script"]').val();
    var oo = {
        server: server,
        message_server: message_server,
        oc_server: oc_server,
        account: account,
        instance: instance,
        build_number:'*',
        version:'*',
        min_builds: '',
        pid: pid,
        token: token,
        username: '',
        instance_name: instance_name,
        instance_url: instance_url,
        allow_script: allow_script
    }
    $.ajax({
        url: 'http://127.0.0.1:4999/worker/new/messaging',
        cache: false,
        data: oo,
        dataType: 'json',
        type: 'get',
        crossDomain: true,
        success: function (d) {

        },
        error: function(){

        },
        complete: function(){
        }
    });

});







//
//
// var timestamp = Date.parse(new Date()); ;
// console.log(timestamp);
// var api_secret_key = 'abcd'
// var sign = timestamp + api_secret_key
// var m5 = hex_md5(sign);
// console.log(m5);
//
// // $.post("http://131.16.23.100:82/api/v1.0/getCourtFilesListByConditionLocal",{'timestamp':timestamp,
// //     'sign':m5},function(data){
// //         console.log(data);
// //     }
// // );
//
// $.ajax({
//     url: 'http://131.16.23.100:82/api/v1.0/getCourtFilesListByConditionLocal',
//     cache: false,
//     data: {'timestamp':timestamp,
//         'sign':m5,
//         'jbfy':'104'},
//     dataType: 'json',
//     type: 'post',
//     crossDomain: true,
//     success: function (d) {
//         console.log(d);
//         console.log(d);
//
//     },
//     error: function(){
//         console.log("失败");
//     },
//     complete: function(){
//
//     }
// });